package com.chenwenxi.trello;

import java.util.HashMap;
import java.util.Map;

import jodd.http.HttpBrowser;
import jodd.http.HttpRequest;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class TrelloClient {
	private final HttpBrowser browser = new HttpBrowser();
	private final String url = "https://api.trello.com/1";

	private final String key = "e73615c79cf7e381aef91c85936e9553";
	private final String token = "7b1a036826a7c49c813f39af1fb3846cc2793716b36ad7423173559b880229a3";
	
	
	public void search() {
		Map<String,String> params = new HashMap<>();
		params.put("query", "me");
		params.put("cards_limit", "100");
		params.put("cards_page","1");
		params.put("key", key);
		params.put("token", token);
		
		browser.sendRequest(HttpRequest.get(url+"/search").query(params));
		log.info(browser.getHttpRequest().hostUrl() + browser.getHttpRequest().queryString());
		String json = browser.getPage();
		log.info(json);
	}
	
	public void cards() {
//		https://api.trello.com/1/boards/5c26e80946f782688488a8f4/cards
		
		Map<String,String> params = new HashMap<>();
		
		params.put("key", key);
		params.put("token", token);
		
		browser.sendRequest(HttpRequest.get(url+"/boards/5c26e80946f782688488a8f4/cards").query(params));
		log.info(browser.getHttpRequest().hostUrl() + browser.getHttpRequest().queryString());
		String json = browser.getPage();
		log.info(json);
	}

	public static void main(String[] args) {	
		TrelloClient trelloClient = new TrelloClient();
//		trelloClient.search();
		trelloClient.cards();
	}
}
